package cn.iocoder.yudao.module.resource.service.directorybaseinfo;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.resource.controller.admin.directorybaseinfo.vo.*;
import cn.iocoder.yudao.module.resource.dal.dataobject.directorybaseinfo.DirectoryBaseInfoDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.resource.dal.mysql.directorybaseinfo.DirectoryBaseInfoMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;

/**
 * 接口基本信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class DirectoryBaseInfoServiceImpl implements DirectoryBaseInfoService {

    @Resource
    private DirectoryBaseInfoMapper directoryBaseInfoMapper;


    @Override
    public String createDirectoryBaseInfo(DirectoryBaseInfoSaveReqVO createReqVO) {
        DirectoryBaseInfoDO infoDO = BeanUtils.toBean(createReqVO, DirectoryBaseInfoDO.class);
        directoryBaseInfoMapper.insert(infoDO);
        return null;
    }

    @Override
    public void updateDirectoryBaseInfo(DirectoryBaseInfoSaveReqVO updateReqVO) {
        // 更新
        DirectoryBaseInfoDO updateObj = BeanUtils.toBean(updateReqVO, DirectoryBaseInfoDO.class);
        directoryBaseInfoMapper.updateById(updateObj);
    }

    @Override
    public void deleteDirectoryBaseInfo(String id) {
        // 校验存在
        validateDirectoryBaseInfoExists(id);
        // 删除
        directoryBaseInfoMapper.deleteById(id);
    }

    @Override
        public void deleteDirectoryBaseInfoListByIds(List<String> ids) {
        // 删除
        directoryBaseInfoMapper.deleteByIds(ids);
        }


    private void validateDirectoryBaseInfoExists(String id) {
        if (directoryBaseInfoMapper.selectById(id) == null) {
            throw exception(new ErrorCode(500,"不存在"));
        }
    }

    @Override
    public DirectoryBaseInfoDO getDirectoryBaseInfo(String id) {
        return directoryBaseInfoMapper.selectById(id);
    }

    @Override
    public PageResult<DirectoryBaseInfoDO> getDirectoryBaseInfoPage(DirectoryBaseInfoPageReqVO pageReqVO) {
        return null;
    }

}